package net.csdn.business.notify.common.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.notify.common.model.entity.NotifyUserSetting;
import net.csdn.business.notify.common.model.query.NotifyUserSettingQuery;
import net.csdn.business.notify.common.model.vo.NotifyUserSettingVO;
import net.csdn.business.notify.common.model.vo.UserNotifySettingVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 通知中心-用户通知配置Mapper接口
 * 
 * @author ruoyi
 * @date 2023-11-27
 */
public interface NotifyUserSettingMapper extends BaseMapper<NotifyUserSetting>
{

    /**
     * 分页查询通知中心-用户通知配置列表
     *
     * @param query 字典类型信息
     * @return 字典类型集合信息
     */
    public List<NotifyUserSettingVO> findPageList(Page page, @Param("query") NotifyUserSettingQuery query);

    /**
     * 查询通知中心-用户通知配置
     * 
     * @param id 通知中心-用户通知配置主键
     * @return 通知中心-用户通知配置
     */
    public NotifyUserSettingVO selectNotifyUserSettingById(String id);

    /**
     * 查询通知中心-用户通知配置列表
     * 
     * @param query 通知中心-用户通知配置
     * @return 通知中心-用户通知配置集合
     */
    public List<NotifyUserSettingVO> selectNotifyUserSettingList(@Param("query") NotifyUserSettingQuery query);

    /**
     * 新增通知中心-用户通知配置
     * 
     * @param notifyUserSetting 通知中心-用户通知配置
     * @return 结果
     */
    public Integer insertNotifyUserSetting(NotifyUserSetting notifyUserSetting);

    /**
     * 修改通知中心-用户通知配置
     * 
     * @param notifyUserSetting 通知中心-用户通知配置
     * @return 结果
     */
    public Integer updateNotifyUserSetting(NotifyUserSetting notifyUserSetting);

    /**
     * 删除通知中心-用户通知配置
     * 
     * @param id 通知中心-用户通知配置主键
     * @return 结果
     */
    public Integer deleteNotifyUserSettingById(String id);

    @Results(id="batchQuery",value={
            @Result(property = "setting",column = "setting",typeHandler = com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler.class)
    })
    @Select("<script> select * from notify_user_setting where 1=1 " +
            "<if test='query.targetType != null and query.targetType!=\"\"' >" +
            " AND target_type=#{query.targetType} " +
            "</if>" +
            "<if test='query.act != null  and query.act!=\"\"'>" +
            " AND act=#{query.act} " +
            "</if>" +
            "<if test='query.userIds != null ' >" +
            " and user_id in " +
            "<foreach collection='query.userIds' item='userId' open='(' separator=',' close=')' >" +
            " #{userId}" +
            "</foreach>" +
            "</if>" +
            "</script>")
    public List<NotifyUserSettingVO> batchQuery(@Param("query") NotifyUserSettingQuery query);



    @Results(id="detail",value={
            @Result(property = "setting",column = "setting",typeHandler = com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler.class)
    })
    @Select("<script> select * from notify_user_setting where target_type= #{targetType} " +
            " AND act= #{act} " +
            " AND user_id = #{userId} " +
            "</script>")
    public NotifyUserSettingVO selectNotifyUserSetting(@Param("targetType")String targetType,@Param("act")String act,@Param("userId")String userId);


    @Results(id="userSettingList",value={
            @Result(property = "setting",column = "setting",typeHandler = com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler.class)
    })
    @Select("<script> select * from notify_user_setting " +
            " where  user_id = #{currUserId} " +
            "</script>")
    public List<UserNotifySettingVO> getUserNotifySetting(@Param("currUserId")String currUserId);
}
